<?php
/**
 * @see Epic_Cache_Interface
 */
require_once 'Epic/Cache/Interface.php';

/**
 * @category   Epic
 * @package    Epic_Cache
 * @author     Epic Core Team <rukanhitokiri@gmail.com>
 */
class Epic_Cache_Handler
{
	/**
	 * Cache object
	 * @var Epic_Cache_Interface
	 */
    protected $_cache;
   
    /**
     * Constructor
     * 
     * Init cache object
     * 
     * @param string $type type identified cache object
     */
    public function __construct($type = '')
    {
    	switch (strtoupper($type)) {
    		case 'DATA': 
    			$this->_cache = new Epic_Cache_Data();
    			break;
    		case 'CONTENT':
    			$this->_cache = new Epic_Cache_Content();
    			break;
    		case 'APC':
    			$this->_cache = new Epic_Cache_Apc();
    			break;
    		default:
    			$this->_cache = new Epic_Cache_Data();
    	}
    }
    
    /**
     * Set cache directory
     * 
     * @param string $cacheDir cache directory
     * @return Epic_Cache_Handler
     */
    public function setCacheDir($cacheDir = '')
    {
    	$this->_cache->setCacheDir($cacheDir);
    	return $this;
    }
    
    /**
     * Set time to keep the cache files
     *
     * @param int $seconds time to keep the cache files
     * @return Epic_Cache_Handler
     */
    public function setExpireTime($seconds)
    {
    	$this->_cache->setExpireTime($seconds);
    	return $this;
    }
    
    /**
     * Check if the cache file exists
     * 
     * @param string $file name file cache
     * @return boolean
     */
    public function exists($file)
    {
    	return $this->_cache->exists($file);
    }
   
    /**
     * Save data to the cache
     * 
     * @param string $file name file cache
     * @param string $data data store
     * @return Epic_Cache_Handler
     */
     public function set($file, $data)
     {
         $this->_cache->set($file, $data);
         return $this;
     }
    
     /**
      * Retrieve data from the cache
      * 
      * @param string $file name file cache
      * @return null|string data from the cache file
      */
     public function get($file)
     {
         return $this->_cache->get($file);
     }
    
     /**
      * Delete the cache file
      * 
      * @param string $file name file cache
      * @return boolean
      */
     public function delete($file)
     {
         return $this->_cache->delete($file);
     }         
}